package photobox.manage

import grails.converters.JSON
import photobox.BaseController
import photobox.photo.Photo
import photobox.utils.ParamUtils
import photobox.utils.ResultUtil

class MngPhotoController extends BaseController {
    def photoService

    def index() {}

    def list() {
        if(params.photoId){
            def photo = Photo.get(params.photoId)
            photo.isRecommend =Integer.parseInt(params.state);
            def display_photo = Photo.get(params.display_photoId)
            display_photo.display = Integer.parseInt(params.statePlay);
            photo.save()
            display_photo.save()
        }
        def searchParams = ParamUtils.parseFilter(params.filters)
        def pageParams = ParamUtils.parsePage(params)
        def sortParams = ParamUtils.parseSort(params,
                ["id", "name", "device", "price", "picTime", "dateCreated", "laudNum", "shareNum", "saleNum", "isDeal", "display","isRecommend"],
                [sort: 'id', order: "desc"])
        def photoRs = photoService.listPhoto(searchParams, pageParams, sortParams)
        render ResultUtil.pageResults(photoRs.rs, photoRs.total, pageParams,
                [id: 'id', name: 'name', device: 'device', price: 'price', picTime: 'picTime', dateCreated: 'dateCreated',
                 laudNum: 'laudNum', shareNum: 'shareNum', saleNum: 'saleNum', isDeal: 'isDeal',display:'display', isRecommend:'isRecommend']) as JSON
    }
}
